package com.hpxx.ylzswl.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.hpxx.ylzswl.R;
import com.hpxx.ylzswl.base.BaseActivity;
import com.hpxx.ylzswl.https.HttpAddress;
import com.hpxx.ylzswl.https.RequestParams;
import com.universal.frame.generalutils.JsonUtil;
import com.universal.frame.generalutils.ToastUtil;
import com.universal.frame.okhttp.OKHttpUtils;
import com.universal.frame.okhttp.ResultCallBack;

import java.io.IOException;

import okhttp3.Request;

/**
 * 云码科技.All rights reserved
 * @ClassName AmendLoginPwdActivity
 * @TitleName 修改登录密码
 * @author LuoXiang
 * @Data 2017-6-16 上午2:07:40
 */
public class AmendLoginPwdActivity extends BaseActivity implements ResultCallBack
		,View.OnClickListener{

	private EditText mEditTextYPwd; //原密码
	private EditText mEditTextXPwd; //新密码
	private EditText mEditTextComAlxPwd; //确认新密码
	private Button btn_al_com;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_amend_loginpwd);
		back();
		setTitle("修改登录密码");
	}
	
	@Override
	public void initView() {
		mEditTextYPwd = (EditText) findViewById(R.id.et_input_aly_pwd);
		mEditTextXPwd = (EditText) findViewById(R.id.et_input_alx_pwd);
		mEditTextComAlxPwd = (EditText) findViewById(R.id.et_amend_com_alx_pwd);
		btn_al_com = (Button) findViewById(R.id.btn_al_com);
		btn_al_com.setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.btn_al_com:
				post();
				break;


			default:
				break;
		}
	}
	

	private void post() {
		String yPwd = mEditTextYPwd.getText().toString().trim();
		String xPwd = mEditTextXPwd.getText().toString().trim();
		String comXPwd = mEditTextComAlxPwd.getText().toString().trim();
		
		if(TextUtils.isEmpty(yPwd)){
			ToastUtil.showToast(this, "请输入原密码");
			return;
		}
		
		if(TextUtils.isEmpty(xPwd)){
			ToastUtil.showToast(this, "请输入新密码");
			return;
		}
		
		if(TextUtils.isEmpty(comXPwd)){
			ToastUtil.showToast(this, "请输入再次新密码");
			return;
		}
		
		if(!xPwd.equals(comXPwd)){
			ToastUtil.showToast(this, "两次密码输入不一致");
			return;
		}
		
		OKHttpUtils.postAsync(this
				, HttpAddress.UP_DATA_LOGIN_PWD_URL
				, new RequestParams(this).getUpdatePwdParams(yPwd, xPwd,3)
		        , this
		        ,R.string.hint_text_set_data, 1);

	}

	@Override
	public void onSuccess(String response, int flag) {
		String status = JsonUtil.getString(response, "status","");
		if("1".equals(status)){
			ToastUtil.showToast(this, "您的密码修改成功，请牢记新密码！");
			finish();
		}else{
			String msg = JsonUtil.getString(response, "msg", "");
			ToastUtil.showToast(this, msg);
		}
	}

	@Override
	public void onFailure(Request request, IOException e, int flag) {
		
	}


}
